package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.coinStoreOrder.CoinRecorderData;
import com.zhongxi.guoyuan.utils.CommonTool;

import java.util.List;

/**
 * Created by Administrator on 2016/12/10.
 */

public class CoinRecorderAdapter extends BaseAdapter {

    private Context context;
    private List<CoinRecorderData> list;

    public CoinRecorderAdapter(Context context, List<CoinRecorderData> data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_coin_recorder, parent, false);
            holder.linearRecorder = (LinearLayout) convertView.findViewById(R.id.linearRecorder);
            holder.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
            holder.tvPhone = (TextView) convertView.findViewById(R.id.tvPhone);
            holder.tvNum = (TextView) convertView.findViewById(R.id.tvNum);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(position%2==0){
            holder.linearRecorder.setBackgroundColor(context.getResources().getColor(R.color.bg_box_one));
        }else{
            holder.linearRecorder.setBackgroundColor(context.getResources().getColor(R.color.bg_box_two));
        }
        if(null!=list.get(position)){
            CoinRecorderData data = list.get(position);
            if(null!=data.getCtime()&&!"".equals(data.getCtime())){
                holder.tvTime.setText(data.getCtime());
            }else{
                holder.tvTime.setText("");
            }
            if(null!=data.getPrice()&&!"".equals(data.getPrice())){
                holder.tvNum.setText(data.getPrice());
            }else{
                holder.tvNum.setText("");
            }
            if(null!=data.getUserphone()&&!"".equals(data.getUserphone())){
                holder.tvPhone.setText(CommonTool.formatPhone(data.getUserphone()));
            }else{
                holder.tvPhone.setText("");
            }
        }
        return convertView;
    }

    class ViewHolder{
        private LinearLayout linearRecorder;
        private TextView tvTime;
        private TextView tvPhone;
        private TextView tvNum;
    }
}
